<?php

class ClassesModel extends RelationModel {

    protected $_link = array(
        'Article' => array(
            'mapping_type' => HAS_MANY,
            'mapping_name' => 'Article',
            'class_name' => 'Article',
            'foreign_key' => 'class_id',
        ),
    );

    public function getList($map, $field) {
        $order = array('class_order' => 'ASC', 'class_id' => 'ASC');
        $map['class_using'] = 1;
        $field = !empty($field) ? $field : true;
        $rs = $this->relation(true)->field($field)->where($map)->order($order)->select();
        dump($this->getLastSql());
        return $rs;
    }

    public function getDetail($id = 0) {
        return $this->field(true)->find($id);
    }

    public function getCategory($id) {
        $result = $this->query("SELECT *,CONCAT(class_path,'-',class_id) AS path FROM `fy_classes` WHERE CONCAT(class_path,'-',class_id) LIKE '0-{$id}%' ORDER BY path;");
        foreach ($result as $key => $value) {
            $space = substr_count($value['path'], '-');
            dump($space);
        }
        return $result;
    }

}
